home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / DOS.SWG / 0085_Detection of WILDCARDS.pas < prev    next >
Pascal/Delphi Source File  |  1995-03-03  |  3KB  |  82 lines

  1. {
  2. Here's a little routine I wrote that checks to see if S1=S2, with wildcards (?
  3. or *)...  IE, Wildcard('TURBO.PAS','T?R*.?AS') will return TRUE.
  4.  
  5. Let me know if you find it useful...
  6.  
  7. Released for SWAG...
  8. }
  9.  
  10. Function Wildcard(S1,S2:String):Boolean;
  11. Var STmp1 : String[8];
  12.     STmp2 : String[3];
  13.     SS1, SS2 : String[12];
  14.     I : Integer;
  15. begin
  16.   STmp1:=Copy(S1,1,Pos('.',S1+'.'))+'????????';
  17.   If (Pos('.',S1)>1) then STmp2:=Copy(S1,Pos('.',S1)+1,3)+'???' else
  18. STmp2:='???';  For I:=1 to 8 do If STmp1[I]='*' then For I:=I to 8 do
  19. STmp1[I]:='?';  For I:=1 to 3 do If STmp2[I]='*' then For I:=I to 3 do
  20. STmp2[I]:='?';  SS1:=STmp1+'.'+STmp2;
  21.   STmp1:=Copy(S2,1,Pos('.',S2+'.'))+'????????';
  22.   If (Pos('.',S2)>1) then STmp2:=Copy(S2,Pos('.',S2)+1,3)+'???' else
  23. STmp2:='???';  For I:=1 to 8 do If STmp1[I]='*' then For I:=I to 8 do
  24. STmp1[I]:='?';  For I:=1 to 3 do If STmp2[I]='*' then For I:=I to 3 do
  25. STmp2[I]:='?';  SS2:=STmp1+'.'+STmp2; WildCard:=False;
  26.   For I:=1 to 12 do If (UpCase(SS1[I])<>UpCase(SS2[I])) and (SS2[I]<>'?') then
  27. Exit;  WildCard:=True;
  28. end;
  29.  
  30.  
  31. --- GoldED 2.40
  32.  * Origin: Crazy Train BBS (604)383-2201  (1:340/88)
  33. SEEN-BY: 340/1 49 60 67 88 211 396/1 3615/50 51
  34. PATH: 340/88 1 3615/50
  35.                                                   
  36. {SWAG=???.SWG,JORGEN OLSSON,Wild cards}
  37. MSGID: 2:205/201@fidonet 94931c10
  38. REPLY: 1:249/153.0 2ea83a7a
  39. PID: GE 1.01+
  40. Hello, John!
  41.  
  42.  > I'm looking for some sort of function to return that:
  43.  > SOMEFILE.TXT = SOM*.TX?
  44.  
  45.  > Function WildCompare(str1,st2: String): boolean;
  46.  
  47. Hope you'll find this one useful to you. Not very beautiful (this message
  48. editor is obviously not made for writing pascal source :)), but it works.
  49.  
  50. ---cut---
  51.  
  52. FUNCTION WildComp(wild,name:string):boolean;
  53. BEGIN
  54.    WildComp:=FALSE;
  55.    if name = '' then exit;
  56.    CASE wild[1] of
  57.       '*' : BEGIN
  58.               if name[1]='.' then exit;
  59.               if length(wild)=1 then WildComp:=TRUE;
  60.               if (length(wild) > 1) and (wild[2]='.') and (length(name) > 0)
  61.               then WildComp:=WildComp(copy(wild,3,length(wild)-2),
  62.                    copy(name,pos('.',name)+1,length(name)-pos('.',name)));
  63.             END;
  64.  
  65.        '?': BEGIN
  66.               if ord(wild[0])=1
  67.                  then WildComp:=TRUE
  68.                  else WildComp:=WildComp(copy(wild,2,length(wild)-1),
  69.                                          copy(name,2,length(name)-1));
  70.             END;
  71.  
  72.        ELSE if name[1] = wild[1]
  73.                  then if length(wild) > 1
  74.                       then WildComp:=WildComp(copy(wild,2,length(wild)-1),
  75.                                               copy(name,2,length(name)-1))
  76.                       else if (length(name)=1)
  77.                            and (length(wild)=1)
  78.                            then WildComp:=TRUE
  79.                  else WildComp:=FALSE;
  80.    END;
  81. END;
  82.